﻿namespace PMS.Client.FrmFile
{
    using PMS.BLL;
    using PMS.Client.Controls;
    using PMS.Client.FrmReport;
    using PMS.Client.Properties;
    using PMS.Common;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;
    using PMS.Model;

    public class FrmList : Form
    {
        private DataGridViewTextBoxColumn AddDate;
        private FileBLL bll = new FileBLL();
        private ToolStripButton btnAdd;
        private ToolStripButton btnDelete;
        private ToolStripButton btnOpen;
        private ToolStripButton btnUpdate;
        private IContainer components = null;
        private UCDataGridView dataGridView1;
        private DataGridViewTextBoxColumn FileID;
        private DataGridViewTextBoxColumn FileName;
        private DataGridViewTextBoxColumn filePath;
        private DataGridViewTextBoxColumn FileSize;
        private Label lbTitle;
        private ToolStrip toolStrip1;

        public FrmList()
        {
            this.InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
            this.DataBind();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAdd add = new FrmAdd();
            add.ShowDialog();
            if (add.DialogResult == DialogResult.OK)
            {
                this.DataBind();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if ((this.dataGridView1.SelectedRows != null) && (this.dataGridView1.SelectedRows.Count > 0))
            {
            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if ((this.dataGridView1.SelectedRows != null) && (this.dataGridView1.SelectedRows.Count > 0))
            {
                try
                {
                    Process.Start(Application.StartupPath + this.dataGridView1.SelectedRows[0].Cells["filePath"].Value.ToString());
                }
                catch (Exception exception)
                {
                    PMS.Common.Log.Write(exception.Message);
                    MessageBox.Show("打开文件失败");
                }
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if ((this.dataGridView1.SelectedRows != null) && (this.dataGridView1.SelectedRows.Count > 0))
            {
                FrmUserReportDesign design = new FrmUserReportDesign(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["ReportID"].Value));
                design.ShowDialog();
                if (design.DialogResult == DialogResult.OK)
                {
                    this.DataBind();
                }
            }
        }

        private void DataBind()
        {
            List<File> list = this.bll.GetList();
            this.dataGridView1.DataSource = list;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmList));
            this.lbTitle = new Label();
            this.toolStrip1 = new ToolStrip();
            this.btnAdd = new ToolStripButton();
            this.btnUpdate = new ToolStripButton();
            this.btnDelete = new ToolStripButton();
            this.dataGridView1 = new UCDataGridView(this.components);
            this.btnOpen = new ToolStripButton();
            this.FileID = new DataGridViewTextBoxColumn();
            this.filePath = new DataGridViewTextBoxColumn();
            this.FileName = new DataGridViewTextBoxColumn();
            this.FileSize = new DataGridViewTextBoxColumn();
            this.AddDate = new DataGridViewTextBoxColumn();
            this.toolStrip1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.lbTitle.BackColor = Color.Gold;
            this.lbTitle.Dock = DockStyle.Top;
            this.lbTitle.Font = new Font("宋体", 14.25f, FontStyle.Bold, GraphicsUnit.Point, 0x86);
            this.lbTitle.ForeColor = Color.Black;
            this.lbTitle.Location = new Point(0, 0);
            this.lbTitle.Name = "lbTitle";
            this.lbTitle.Size = new Size(0x377, 0x27);
            this.lbTitle.TabIndex = 12;
            this.lbTitle.Text = "文件列表";
            this.lbTitle.TextAlign = ContentAlignment.MiddleCenter;
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.btnAdd, this.btnUpdate, this.btnDelete, this.btnOpen });
            this.toolStrip1.Location = new Point(0, 0x27);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.RenderMode = ToolStripRenderMode.System;
            this.toolStrip1.Size = new Size(0x377, 0x38);
            this.toolStrip1.TabIndex = 15;
            this.toolStrip1.Text = "toolStrip1";
            this.btnAdd.Image = Resources.Icons_add;
            this.btnAdd.ImageScaling = ToolStripItemImageScaling.None;
            this.btnAdd.ImageTransparentColor = Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new Size(60, 0x35);
            this.btnAdd.Text = "添加文件";
            this.btnAdd.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
            this.btnUpdate.Image = Resources.Icons_update;
            this.btnUpdate.ImageScaling = ToolStripItemImageScaling.None;
            this.btnUpdate.ImageTransparentColor = Color.Magenta;
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new Size(60, 0x35);
            this.btnUpdate.Text = "修改文件";
            this.btnUpdate.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnUpdate.Click += new EventHandler(this.btnUpdate_Click);
            this.btnDelete.Image = Resources.delete;
            this.btnDelete.ImageScaling = ToolStripItemImageScaling.None;
            this.btnDelete.ImageTransparentColor = Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new Size(60, 0x35);
            this.btnDelete.Text = "删除文件";
            this.btnDelete.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnDelete.Click += new EventHandler(this.btnDelete_Click);
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.BackgroundColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            this.dataGridView1.BorderStyle = BorderStyle.None;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.FileID, this.filePath, this.FileName, this.FileSize, this.AddDate });
            style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            style.Font = new Font("宋体", 9f);
            style.ForeColor = Color.Black;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = Color.Black;
            style.WrapMode = DataGridViewTriState.True;
            this.dataGridView1.DefaultCellStyle = style;
            this.dataGridView1.Dock = DockStyle.Fill;
            this.dataGridView1.GridColor = Color.FromArgb(0xd0, 0xd7, 0xe5);
            this.dataGridView1.HighlightSelectedColumnHeaders = false;
            this.dataGridView1.Location = new Point(0, 0x5f);
            this.dataGridView1.MultiSelect = false;
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new Size(0x377, 0x180);
            this.dataGridView1.TabIndex = 13;
            this.btnOpen.Image = Resources.view;
            this.btnOpen.ImageScaling = ToolStripItemImageScaling.None;
            this.btnOpen.ImageTransparentColor = Color.Magenta;
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new Size(60, 0x35);
            this.btnOpen.Text = "打开文件";
            this.btnOpen.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnOpen.Click += new EventHandler(this.btnOpen_Click);
            this.FileID.DataPropertyName = "FileID";
            style2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style2.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.FileID.DefaultCellStyle = style2;
            this.FileID.HeaderText = "FileID";
            this.FileID.Name = "FileID";
            this.FileID.ReadOnly = true;
            this.FileID.Visible = false;
            this.FileID.Width = 30;
            this.filePath.DataPropertyName = "FilePath";
            this.filePath.HeaderText = "FilePath";
            this.filePath.Name = "filePath";
            this.filePath.ReadOnly = true;
            this.filePath.Visible = false;
            this.FileName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            this.FileName.DataPropertyName = "FileName";
            this.FileName.HeaderText = "文件名";
            this.FileName.Name = "FileName";
            this.FileName.ReadOnly = true;
            this.FileSize.DataPropertyName = "FileSize";
            this.FileSize.HeaderText = "文件大小";
            this.FileSize.Name = "FileSize";
            this.FileSize.ReadOnly = true;
            this.FileSize.Width = 150;
            this.AddDate.DataPropertyName = "AddDate";
            this.AddDate.HeaderText = "添加时间";
            this.AddDate.Name = "AddDate";
            this.AddDate.ReadOnly = true;
            this.AddDate.Width = 150;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x377, 0x1df);
            base.Controls.Add(this.dataGridView1);
            base.Controls.Add(this.toolStrip1);
            base.Controls.Add(this.lbTitle);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "FrmList";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "文件列表";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

